package io.leo.leoui.viewgroups;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

public class SlideRecyclerView extends RecyclerView {
    //是子View的事件还是父View的事件
    private int who = IS_UNKNOW;
    private static final int IS_CHILD=0,IS_SELF=1,IS_UNKNOW=2;
    private float startY,startX;

    public SlideRecyclerView(Context context) {
        super(context);
    }

    public SlideRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public SlideRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent e) {
        if (e.getAction()==MotionEvent.ACTION_DOWN){
            startY = e.getRawY();
            startX = e.getRawX();
        }else if(e.getAction()==MotionEvent.ACTION_MOVE&&who==IS_UNKNOW){
            if (Math.abs(e.getRawX()-startX)>20)
                who=IS_CHILD;
            else if (Math.abs(e.getRawY()-startY)>20)
                who=IS_SELF;
        }else if (e.getAction()==MotionEvent.ACTION_UP){
            who=IS_UNKNOW;
            startY=0;startX=0;
        }
        Log.i("srvwhoishe", String.valueOf(who));
        Log.i("srvsx&sy",startX+","+startY);
        Log.i("srvx&y",Math.abs(e.getRawX()-startX)+","+Math.abs(e.getRawY()-startY));
        return who==IS_SELF;
    }
}
